#include <bits/stdc++.h>
#include <string>
using namespace std;

class Solution {
public:
    int monotoneIncreasingDigits(int n) {
        int ans = 0;
        string str = to_string(n);
        int index = 0;
        while(index+1<str.size() && str[index]<=str[index+1]) ++index;
        if(index < str.length()){
            while(index>0 && str[index-1]>str[index]){
                --str[index-1];
                --index;
            }
            for(index+=1; index<str.length(); ++index){
                str[index] = '9';
            }
        }
        return stoi(str);
    }
};